package com.guchenbo.scala.c1

/**
 * class Student的伴生对象
 *
 * @author guchenbo
 * @date 2022/3/15
 */
object Student {

  def main(args: Array[String]): Unit = {
    val student = new Student
    println("#############")
    new Student("na")
    println("#############")
    new Student("na", 12)

    student("sss")

    student.apply("a")
  }
}

class Student { // 主构造器，无参数
  println("主构造器调用")

  // _表示初始值，String就是null，Int就是0
  var name: String = _
  var age: Int = _

  def this(name: String) {
    this()
    this.name = name
    println("辅助构造器1调用")
  }

  def this(name: String, age: Int) {
    this(name)
    this.age = age
    println("辅助构造器2调用")
  }

  println(s"name=$name, age=$age")

  def apply(s:String): Unit ={
    println(s)
  }
}

